import subprocess
import matplotlib.pyplot as plt

# 调用C程序（注意路径指向编译后的可执行文件）
process = subprocess.Popen(["./cmake-build-debug/Visual"],
                           stdout=subprocess.PIPE)
x, y = [], []
for line in process.stdout:
    xi, yi = map(float, line.decode().split())
    x.append(xi)
    y.append(yi)

# 绘制图形
plt.plot(x, y, 'ro-', label='sin(x)')
plt.title("C Generated Data Visualized in Python")
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.legend()
plt.grid(True)
plt.show()